let arr = [1, 2, [3, [4]]]
//将数组扁平化，就是变为一维数组
function flattenArray(arr) {
  let newArr = []
  for (let key in arr) {
    if (Array.isArray(arr[key])) {
      //newArr.push(...flattenArray(arr[key]))
      newArr = newArr.concat(flattenArray(arr[key]))// concat() 会返回一个新数组
    } else {
      newArr.push(arr[key])
    }
  }
  return newArr
}
console.log(flattenArray(arr));
